package ssau.knyazev.cafe.model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import javax.swing.AbstractListModel;

import ssau.knyazev.common.UniException;
import ssau.knyazev.db.core.ConnectionHelper;




public class OrderListModel extends AbstractListModel {

	private static final long serialVersionUID = 7919644590621710930L;
	private List<Order> elements = null;
	private static final String loadQuery = "select order_id from cafe_orders";
	
	public OrderListModel() throws UniException{
		elements = Order.loadAll();
	}
	
	/*private static List<String> loadIDs() throws UniException{
		List<String> ids = new LinkedList<String>();
		Connection con = ConnectionHelper.getConnection();
		PreparedStatement state = null;
		try {
			state = con.prepareStatement(loadQuery);
			ResultSet rs = state.executeQuery();
			while (rs.next()){
				ids.add(rs.getString("order_id"));
			}
			return ids;
		} catch (SQLException e) {
			throw new UniException("Could not perform query:\n" + loadQuery, e);
		} finally {
			ConnectionHelper.closeConnection(con, state);
		}
	}*/
	
	public Object getElementAt(int index) {
		return elements.get(index);
	}

	public int getSize() {
		return elements.size();
	}

}
